package com.hzcx.app.simplechat.ui.user.presenter;

import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.model.FriendModel;
import com.hzcx.app.simplechat.model.UserModel;
import com.hzcx.app.simplechat.ui.publicui.bean.HxUserInfoBean;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.ui.user.contract.UserInfoContract;
import com.hzcx.app.simplechat.ui.user.contract.UserRemarkContract;
import com.hzcx.app.simplechat.util.UserInfoUtil;

import org.litepal.LitePal;
import org.litepal.crud.callback.FindCallback;

public class UserRemarkPresenter extends BasePresenter<UserRemarkContract.View> implements UserRemarkContract.Presenter {

    /**
     * 设置备注名及描述
     *
     * @param context
     * @param id
     * @param remarks_name
     * @param description
     */
    @Override
    public void setRemarkAndDes(Context context, int id, String remarks_name, String description) {
        UserModel.setUserRemarkName(context, id, remarks_name, description, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.showLoading();
                LitePal.where("member_id=? and myUserId=?", id + "", UserInfoUtil.getUserId() + "")
                        .findFirstAsync(HxUserInfoBean.class).listen(userInfoBean -> {
                            if (userInfoBean != null) {
                                userInfoBean.setRemarks_name(remarks_name);
                                userInfoBean.save();
                            }
                            mView.hideLoading();
                            mView.setSuccess();
                        });
            }
        });
    }
}
